package uk.ac.nott.cs.g53dia;
/**
 * A default CellFactory which populates the environment with cells and flowers.
 * 
 * @author Neil Madden
 */

/*
 * Copyright (c) 2005 Neil Madden.
 * Copyright (c) 2010 University of Nottingham.
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

public class DefaultCellFactory implements CellFactory {
    /**
     * Density of flowers.
     */
    protected double density;
    /**
     * Default flower density.
     */
    final static double DEFAULT_FLOWER_DENSITY = 0.05;

    /**
     * Create a DefaultCellFactory.
     * @param density proportion of cells containing flowers
     */
    public DefaultCellFactory(double density) {
        this.density = density;
    }
    public DefaultCellFactory() { this(DEFAULT_FLOWER_DENSITY); }

    /**
     * Create new cells and flowers in the environment.
     * @param env environment to which the cell is to be added
     * @param pos position of the new cell
     */

    public void generateCell(Environment env, Point pos) {
    	if (Math.random() < density) {
    		int type = (int)(Math.random() * Flower.NUM_TYPES);
    		env.putCell(new Flower(type, -1, pos));
        } else {
        	env.putCell(new EmptyCell(pos));
        }
    }
}
